package com.sales.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;

/**
 * Created by lihu on 2017/9/7.
 * 用户帐户信息
 */
@Data
@Entity
@NoArgsConstructor
public class Account {

    @Id
    @Column(length = 50)
    private String id;

    private String username;


    //总金额
    private int amountTotal = 0;

    //剩余可以提金额
    private int surplusAmount = 0;


    @CreatedBy
    @Column(insertable = false, updatable = false, columnDefinition = "TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3)")
    private Date addTime;

    @LastModifiedDate
    @Column(insertable = false, updatable = false, columnDefinition = "TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)")
    private Date updateTime;

    public Account(String id, String username) {
        this.id = id;
        this.username = username;
    }


    public void addAmount(int amount) {
        this.amountTotal += amount;
        this.surplusAmount += amount;
    }
}
